﻿using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LaunchAllaround.DesignPattern
{
    [Serializable]
    public class Container<T>
    {

        // ############################
        // # pattern Decorator        # 
        protected ArrayList items;
        // ############################

        public Container():this(0){}
        public Container(int i)
        {
            this.items = new ArrayList(i);
        }
        private Container(ArrayList items)
        {
            this.items = (ArrayList)items.Clone();
        }

        public virtual void Add(T item){
            this.items.Add(item);
        }

        public virtual void Remove(T item)
        {
            this.items.Remove(item);
        }

        public virtual void RemoveAt(int i)
        {
            this.items.RemoveAt(i);
        }

        public T Get(int i)
        {
            return (T)this.items[i];
        }

        public virtual void Clear()
        {
            this.items.Clear();
        }

        public virtual void Insert(int i, T item)
        {
            this.items.Insert(i, item);
        }

        public IEnumerator GetEnumerator(){
            return this.items.GetEnumerator();
        }

        public int Count
        {
            get{
                return this.items.Count;  
            }
        }

        protected void AddRange(Container<T> container)
        {
            this.items.AddRange(container.items);
        }

        protected void RemoveRange(int index, int count)
        {
            this.items.RemoveRange(index, count);
        }

        protected void setRange(int index, Container<T> container)
        {
            this.items.SetRange(index, container.items);
        }

        protected void InsertRange(int index, Container<T> container)
        {
            this.items.InsertRange(index, container.items);
        }

        public Container<T> GetRange(int index, int count)
        {
            return new Container<T>(this.items.GetRange(index, count));
        }
    }
}
